package pl.edu.wsinf.lukaszwalczak.emailclient.view;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
import pl.edu.wsinf.lukaszwalczak.emailclient.controller.FindController;

@Component
public class FindView extends BorderPane{
        
    @Inject
    private FindController findController;
    private Stage stage = null;
  
    public void show() {
        if (stage == null) {
            stage = new Stage();
            //resizable disabled
            stage.setResizable(false);
            //create root node of scene, i.e. group
            AnchorPane root = new AnchorPane();
            //create scene with set width, height and color
            Scene scene = new Scene(root, 370, 200, Color.WHITESMOKE);
            //set scene to stage
            stage.setScene(scene);
            stage.setTitle("Szukaj");
            //center stage on screen
            stage.centerOnScreen();
            //show the stage
            stage.show();
    
            double LEFT_PADDING = 20;
            double RIGHT_PADDING = 20;
            double TOP_PADDING = 15;
            double BOTTOM_PADDING = 10;
            double FIELD_SPACING = 25;
            double LABEL_WIDTH = 100;
            double TEXT_FIELD_WIDTH = 250;

            // Pole "Od"
            Label emailLabel = new Label("Od: ");
            emailLabel.setPrefWidth(LABEL_WIDTH);
            final TextField emailTextField = new TextField();
            emailTextField.setPrefWidth(TEXT_FIELD_WIDTH);
            
            // Pole "Do"
            Label emailLabel1 = new Label("Do: ");
            emailLabel1.setPrefWidth(LABEL_WIDTH);
            final TextField emailTextField1 = new TextField();
            emailTextField1.setPrefWidth(TEXT_FIELD_WIDTH);
            
            // Pole "Kopia"
            Label emailLabel2 = new Label("Kopia: ");
            emailLabel2.setPrefWidth(LABEL_WIDTH);
            final TextField emailTextField2 = new TextField();
            emailTextField2.setPrefWidth(TEXT_FIELD_WIDTH);
            
            // Pole "Data"
            Label emailLabel3 = new Label("Data: ");
            emailLabel3.setPrefWidth(LABEL_WIDTH);
            final TextField emailTextField3 = new TextField();
            emailTextField3.setPrefWidth(TEXT_FIELD_WIDTH);
            
            // Pole "Tamt"
            Label emailLabel4 = new Label("Temat: ");
            emailLabel4.setPrefWidth(LABEL_WIDTH);
            final TextField emailTextField4 = new TextField();
            emailTextField4.setPrefWidth(TEXT_FIELD_WIDTH);
            
            // Pole "Treść"
            Label emailLabel5 = new Label("Treść: ");
            emailLabel5.setPrefWidth(LABEL_WIDTH);
            final TextField emailTextField5 = new TextField();
            emailTextField5.setPrefWidth(TEXT_FIELD_WIDTH);
            
            // Przycisk "Szukaj"
            Button btn = ViewHelper.createButton("Szukaj", new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event) {
                }
            }, "find.png", 100d, 20d);   
              
            root.getChildren().addAll(emailLabel, emailTextField, emailLabel1, emailTextField1, emailLabel2, emailTextField2, emailLabel3, emailTextField3, emailLabel4, emailTextField4, emailLabel5, emailTextField5,btn);
            AnchorPane.setTopAnchor(emailLabel, Double.valueOf(TOP_PADDING));
            AnchorPane.setLeftAnchor(emailLabel, Double.valueOf(LEFT_PADDING));
            AnchorPane.setTopAnchor(emailTextField, Double.valueOf(TOP_PADDING));
            AnchorPane.setLeftAnchor(emailTextField, Double.valueOf(LABEL_WIDTH));
            AnchorPane.setTopAnchor(emailLabel1, Double.valueOf(TOP_PADDING + 1 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailLabel1, Double.valueOf(LEFT_PADDING));
            AnchorPane.setTopAnchor(emailTextField1, Double.valueOf(TOP_PADDING + 1 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailTextField1, Double.valueOf(LABEL_WIDTH));
            AnchorPane.setTopAnchor(emailLabel2, Double.valueOf(TOP_PADDING + 2 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailLabel2, Double.valueOf(LEFT_PADDING));
            AnchorPane.setTopAnchor(emailTextField2, Double.valueOf(TOP_PADDING + 2 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailTextField2, Double.valueOf(LABEL_WIDTH));
            AnchorPane.setTopAnchor(emailLabel3, Double.valueOf(TOP_PADDING + 3 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailLabel3, Double.valueOf(LEFT_PADDING));
            AnchorPane.setTopAnchor(emailTextField3, Double.valueOf(TOP_PADDING + 3 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailTextField3, Double.valueOf(LABEL_WIDTH));
            AnchorPane.setTopAnchor(emailLabel4, Double.valueOf(TOP_PADDING + 4 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailLabel4, Double.valueOf(LEFT_PADDING));
            AnchorPane.setTopAnchor(emailTextField4, Double.valueOf(TOP_PADDING + 4 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailTextField4, Double.valueOf(LABEL_WIDTH));
            AnchorPane.setTopAnchor(emailLabel5, Double.valueOf(TOP_PADDING + 5 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailLabel5, Double.valueOf(LEFT_PADDING));
            AnchorPane.setTopAnchor(emailTextField5, Double.valueOf(TOP_PADDING + 5 * FIELD_SPACING));
            AnchorPane.setLeftAnchor(emailTextField5, Double.valueOf(LABEL_WIDTH));
                        
            AnchorPane.setBottomAnchor(btn, BOTTOM_PADDING);
            AnchorPane.setRightAnchor(btn, RIGHT_PADDING);
            
            } else {
            stage.show();
        }
    }   
}
